<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>公司溯源</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <link rel="stylesheet" href="css/capacity.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <section class="AllContent" style="background-color: #fff;">
	    	<div id="piclist">
	    		<!-- 溯源  -->
				<div id="ClothingTtyMain" style="margin-bottom:40px;border-bottom:2px solid #6CC83A;">
					
					<!-- 标题 -->
					<div class="ChothingTtyTitle" style="border-left:2px solid #6CC83A;">
						<i></i>
						<p>产品溯源过程</p>
					</div>
					
					<div style="overflow: hidden;" id="CentralBlock">
						<img style="width: 40%;margin:20px auto;display: block;" src="images/loading5.gif">
					</div>
				</div>
			</div>
	    	
	    	
	    	<section>
	    		<!-- 输入DIV -->
				<div class="theme-popover">
					
					<!-- 标题 -->
		        	<div class="InputNavigation">
		        		<p>公司溯源</p>
		        		<p class="exit"><img src="images/remove1.png"></p>
		        	</div>
		        	
		        	<!-- 商品信息   -->
		        	<div class="AddList">
		        		<div class="CommodityInfo">
		        			<div class="FormStyle">
		        				<ul style="width: 90%;">
			        				<li>网点：</li>
			        				<li>
										<select name="from_branch" id="from_branch">
	                                        <option value="0">选择网点</option>
	                                    </select>
			        				</li>
			        				<li>时间：</li>
			        				<li><input type="date" style="display: block;margin-top:4px;line-height:30px;" name="start_date" id="start_date" placeholder="格式：1000-00-00 00:00"/></li>
		        				
		        				</ul>
			        			
			        			<button class="NextButton" type="button" onclick="addtrack();">保存</button>
		        			</div>
		        		</div>
		        	</div>
				</div>
	    	</section>
				
			<!-- 遮罩层 -->
			<div class="theme-popover-mask"></div>
	    </section>
        
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init({
	    	
	    });
		$(function () {
			$('.AllHeader li:eq(0)').removeClass('mui-action-back mui-pull-left').addClass('tiaozhuan');
			$('.AllHeader li:eq(1)').html("<a class='companyTy'>公司</a><a href='ProductTraceability.html' class='productTy'>产品</a>");
			$('.AllHeader li:eq(2)').html('<img onclick="addtrackbox();" class="theme-login" style="width:22px" src="images/addproducts.png">');
			$('.titleTwo').css({lineHeight:'30px',marginTop:'5px'})
	        $('.ChothingTtyTitle').hide();
            getItemTrackingList();
			
			$('.tiaozhuan').on('tap',function(){
				plus.webview.getWebviewById('CompanyTraceability.html').close();
				window.location.href= 'supper.html';
			});
//			$(".productTy").on('tap',function(){
//				mui.openWindow({
//					url: 'ProductTraceability.html', 
//					id:'ProductTraceability.html',
//					show:{
//				    	aniShow:'none'//页面显示动画，默认为”slide-in-right“；
//				    }
//				});
//			})
			
            /*遮罩*/
            $('.theme-login').click(function(){
				$('.theme-popover-mask').fadeIn(100);
				$('.theme-popover').slideDown(200);
				$('.AllContent').css({overflow:'hidden'});
			})
			$('.theme-popover-mask,.exit,.guanbi').click(function(){
				$('.theme-popover-mask').fadeOut(100);
				$('.theme-popover').slideUp(200);
				$('.AllContent').css({overflowY:'scroll'});
			})
		});
        
        /* 隐藏溯源   */
        function hideTty(){
        	$('.switchq').on('click',function(){
				if($(this).find('.control').prop("checked")){    //判断elect是否被选中
					$(this).find('.SlideImg').animate({left:'-5px'},200,function(){
						$(this).parent('.switchq').addClass('sh2');
						$(this).parents('.TraceabilityPiece').css({opacity:'0.2'});
					});
				}else{
					$(this).find('.SlideImg').animate({left:'40px'},200,function(){
						$(this).parent('.switchq').removeClass('sh2');
						$(this).parents('.TraceabilityPiece').css({opacity:'1'});
					});
					
				}
			})
        }

        function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        function onBackKeyDown() {
            openUrl("index.html");
        }
        function addtrackbox(){
            $.ajax({
                type: "post",
                url: getServerUrl() + "/Open/Company/getbranchlist", //与此php页面沟通
                dataType: 'json', //从php返回的值以 JSON方式 解释
                data: 'access_token='+getToken(), //
                success: function (json) {//如果调用php成功
                    clist = json.branchlist;
                    var chtml = '';
                    var chtmg = '';
                    if (!empty(clist)) {
                        for (var i = 0; i < clist.length; i++) {
                            if (!empty(clist[i])) {
                                chtml = chtml + '<option value="'+ clist[i].bid+'" src="'+ clist[i].branch_pic+'">' + clist[i].name + '</option>';
                            }
                        }
                    }
                    $("#from_branch").append(chtml);
                    $("#to_branch").append(chtml);
                    
                },
                error:function(json){
                    alertMessage(json.error_description);
                }
            });
        }
        function addtrack() {
            var from_branch = $("#from_branch").val();
            var from_name = $("#from_branch").find("option:selected").text();
            var branch_pic = $("#from_branch").find("option:selected").attr("src");
            var to_branch = $("#to_branch").val();
            var to_name = $("#to_branch").find("option:selected").text();
            var start_date = $("#start_date").val();
            
            if (empty(from_branch) || from_branch == 0 ) {
                alertMessage("请选择发货网点！");
                return;
            }
//          if (empty(to_branch) || to_branch == 0 ) {
//              alertMessage("请选择目的网点！");
//              return;
//          }
            if (empty(start_date)) {
                alertMessage("时间不能为空！");
                return;
            }
            var datas = {access_token:getToken(),from_branch:from_branch,to_branch:to_branch,start_date:start_date,branch_pic:branch_pic};
            $.ajax({
                type: "post",
                url: getServerUrl() + "/Open/ComSys/addsource",
                dataType: 'json',
                data: datas,
                success: function (json) {
                    if (json.result == "1") {
                        var html = '';
                        html= html+ '<div class="ChotingTtyLeft">'
								+'<p>'+start_date.substring(0,4)+'</p>'
								+'<p>'+start_date.substring(5)+'</p>'
							+'</div>'
							
							+'<div class="ChotingTtyRight" style="border-left:2px solid #6CC83A;">'
								+'<i></i>'
								+'<p class="SKheightImg"><img width="100%" src="'+branch_pic+'"></p>'
								+'<p class="BranchName2">'+from_name+'</p>'
							+'</div>';
	                    
	                    $("#CentralBlock").prepend(html);
	                    $(".modal-body input").val("");
	                    
						$('.theme-popover-mask').fadeOut(100);
						$('.theme-popover').slideUp(200);
						$('.AllContent').css({overflowY:'scroll'});
						var strwt = $('.SKheightImg').width();
						$('.SKheightImg').height(strwt/2);
						
						
	                    hideTty();
                    } else {
                        alertMessage("添加溯源错误:[" + json.error_description + "]");
                    }
                }
            });
        }
        function getItemTrackingList() {
            $("#datalistid").html("");
            $.ajax({
                type: "post",
                url: getServerUrl() + "/Open/ComSys/comsource",
                dataType: 'json',
                data: "access_token="+getToken(),
                success: function (jdata) {
                    if (jdata.result == "1") {
                       html="";
                       for(var i=0;i<jdata.data.length;i++){
                       		html= html+ '<div class="ChotingTtyLeft">'
								+'<p>'+jdata.data[i].start_date.substring(0,4)+'</p>'
								+'<p>'+jdata.data[i].start_date.substring(5,10)+'</p>'
							+'</div>'
							
							+'<div class="ChotingTtyRight" style="border-left:2px solid #6CC83A;">'
								+'<i></i>'
								+'<p class="SKheightImg"><img width="100%" src="'+jdata.data[i].source_pic+'"></p>'
								+'<p class="BranchName2">'+jdata.data[i].fname+'</p>'
							+'</div>';
                       }
                       
                        $("#CentralBlock").html(html);
	                    $('.ChothingTtyTitle').show();
						var strwt = $('.SKheightImg').width();
						$('.SKheightImg').height(strwt/2);
	                    hideTty();
	                   
                    } else {
                        alert(jdata.error_description);
                    }
                },
                error: function () {
                    //jsonp 方式此方法不被触发.原因可能是dataType如果指定为jsonp的话,就已经不是ajax事件了  
                    //请求出错处理   
                    alert("请求出错(请检查相关度网络状况.)");
                }
            });
        }
         function deleteItemTracking(id) {
            $.ajax({
                type: "get",
                url: getServerUrl() + "/Open/ComSys/deltrack?id="+ id+"&access_token="+getToken(),
                dataType: 'json',
                success: function (jdata) {
                    if (jdata.result == "1") {
                        alertMessage('删除成功');
                        window.location.href = location.href;
                    } else {
                        alert(jdata.error_description);
                    }
                },
                error: function () {
                    alert("请求出错(请检查相关度网络状况.)");
                }
            });
        }
	</script>
</html>
